package com.uinnova.springboot.mail;

import com.uinnova.springboot.mail.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*
*@author 王刚
*@date 2019-01-17 19:43
*
*/

@RestController
public class MailController {

    @Autowired
    private MailService mailService;

    @GetMapping(value = "/jail/mail/simpleMail")
    public void sendSimpleMail() throws Exception{
        mailService.sendSimpleMail("17715331169@163.com","测试发送邮件","hello,这是自动发送的邮件哦");
        System.out.println("发送简单邮件成功");
    }

    @GetMapping(value = "/jail/mail/hemlMail")
    public void  sendHtmlMail(){
        String content="<html>\n" +
                "<body>\n" +
                "    <h3>hello world ! 这是一封html邮件!</h3>\n" +
                "</body>\n" +
                "</html>";
        mailService.sendHtmlMail("17715331169@163.com","测试发送html邮件",content);
        System.out.println("html邮件发送成功");
    }

    @GetMapping(value = "/jail/mail/attachMail")
    public void sendAttachmentMail(){
        String filePath = "C:\\Users\\Administrator\\Desktop\\临时文件\\每日任务.md";
        mailService.sendAttachmentsMail("17715331169@163.com","测试发送带附件的邮件","有附件，请查收",filePath);
        System.out.println("带附件的邮件发送成功");
    }

    @GetMapping(value = "/jail/mail/inlineMail")
    public void  sendInline(){
        String resId = "neo006";
        String content = "<html><body>这是有图片的邮件:<img src=\'cid"+resId+ "\'></body></html>";
        String imgPath = "C:\\Users\\Administrator\\Desktop\\55372456_p0.jpg";
        mailService.sendInlineResourceMail("17715331169","这是有图片的邮件",content,imgPath,resId);
        System.out.println("有图片的邮件发送成功");
    }

}
